﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ini文件读取类Inifile
{
    internal class IniFile
    {
        public Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();

        public void ReadFile(string filepath)
        {
            string[] array = File.ReadAllLines(filepath);
            string mainkey = "";
            for (int i = 0; i < array.Length; i++)
            {
                array[i].Trim();
                if (array[i].StartsWith("["))
                {
                    mainkey = array[i].Substring(1, array[i].Length - 2);
                    dic.Add(mainkey, new Dictionary<string, string>());
                }
                else if (array[i].Contains("="))
                {
                    string[] ky = array[i].Split('=');

                    dic[mainkey].Add(ky[0].TrimEnd(), ky[1].TrimStart());
                }
            }
        }

        public string Getstring(string key1, string key2)
        {
            string s1 = dic[key1][key2];
            return s1;
        }
    }
}